#include "./delay.h"
#include "../compat.h"

void delay_init() {
    RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;

    TIM4->CR1 = 0x00;
    TIM4->CR2 = 0x00;
    TIM4->PSC = 8 - 1;
    TIM4->ARR = 0xFFFF;
    TIM4->EGR = 0x01;
    TIM4->CR1 = 0x01;
}

void delay_us(uint16_t us) {
    TIM4->CNT = 0;
    while ( TIM4->CNT < us ) {}
}

